import React, { Component } from 'react';
import { Link, Redirect } from 'react-router-dom'

class Index extends Component {
    constructor(props) {
        super(props);
        this.state = { 
            list:[
                {id:1,title:'react-route练习1'},
                {id:2,title:'react-route练习2'},
                {id:3,title:'react-route练习3'},
                {id:4,title:'react-route练习4'},
                {id:5,title:'react-route练习5'},
            ],
        }
        this.props.history.push('/home')
        
    }
    
    componentDidMount () {

    }

    render() { 
        return ( 
            <div>
                {/* 标签式重定向 */}
                <Redirect to="/home"/>
                <ul>
                    {
                        this.state.list.map((item, index) => {
                            return (
                                <li key={index}>
                                    <Link to={'/list/'+item.id}> {item.title} </Link>
                                </li>
                            )
                        })
                    }
                </ul>
            </div>
         );
    }
}
 
export default Index;